package org.mybatis.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Select;
import org.mybatis.domain.User;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface UserMapper {

    @Delete("delete from es_user where id = 1")//使⽤#{key}⽅式获取⽅法中的参数值
    public void deleteById(Integer id);

    @Insert("insert into `es_user`(username,password,phone,gender,birthday,register_time) values (#{username},#{password},#{phone},#{gender},#{birthday},#{registerTime})")
    public void insert(User user);

    @Update("update es_user set username= #{username},phone = #{phone},avatar = #{avatar},gender = #{gender},status = #{status},birthday = #{birthday} where id = #{id}")
    public void update(User user);

    @Select("select id,username,password,phone,avatar,gender,status,birthday,register_time from es_user where id=#{id}")
    public User getById(Integer id);

    @Select("select * from es_user " + "where username like '%${name}%' " + "and status = #{status} " + "and register_time between #{begin} and #{end} " + "order by register_time desc")
    public List<User> list(String name, Byte status, LocalDate begin, LocalDate end);

}